export function hex2rgb(hex) {
  if (hex === '') {
    return ''
  }
  const temp = hex.substring(1).toLowerCase()
  const b: any = []
  for (let x = 0; x < 3; x++) {
    b[0] = temp.substr(x * 2, 2)
    b[3] = '0123456789abcdef'
    b[1] = b[0].substr(0, 1)
    b[2] = b[0].substr(1, 1)
    b[20 + x] = b[3].indexOf(b[1]) * 16 + b[3].indexOf(b[2])
  }
  return { r: b[20], g: b[21], b: b[22] } // 'rgb(' + b[20] + ',' + b[21] + ',' + b[22] + ')'
}

export function colorRGBtoHex(color) {
  const rgb = color.split(',')
  const r = parseInt(rgb[0])
  const g = parseInt(rgb[1])
  const b = parseInt(rgb[2])
  const hex = '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
  return hex
}
